package com.rxt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rxt.common.result.Result;
import com.rxt.model.domain.KKonwledge;
import com.rxt.model.domain.KRemark;
import com.rxt.model.domain.UExpert;
import com.rxt.mapper.UExpertMapper;
import com.rxt.model.dto.KKonwledgeDto;
import com.rxt.model.vo.UExpertPageVo;
import com.rxt.service.IUExpertService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 周梓文
 * @since 2023-08-24
 */
@Service
public class UExpertServiceImpl extends ServiceImpl<UExpertMapper, UExpert> implements IUExpertService {

    @Override
    public Result getPage(UExpertPageVo expertPage) {

        String keyWord = expertPage.getKeyWord();

        Page<UExpert> page = new Page<>(expertPage.getPage(), expertPage.getPageSize());

        LambdaQueryWrapper<UExpert> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.like(keyWord!=null,UExpert::getRealName,"%"+keyWord+"%")
                .orderByDesc(UExpert::getCreateTime);

        this.page(page, lambdaQueryWrapper);

        return Result.ok(page);

    }

    @Override
    public Result getOneByID(Long id) {

        //获取专家详细信息
        UExpert one = this.getOne(new LambdaQueryWrapper<UExpert>().eq(UExpert::getUserId, id));
        if (one == null){
            return Result.fail("没有该知识");
        }

        //返回结果
        return Result.ok(one);
    }

    @Override
    public Result dedleteById(Long id) {

        this.removeById(id);

        return Result.ok("删除成功");
    }

    @Override
    public Result updateExpertById(UExpert expert) {

        this.updateById(expert);

        return Result.ok("修改成功");
    }
}
